﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;

namespace MusicPlow
{
    public class SingleResultStatistic
    {
        public TimeSpan YoutubeTime { get; private set; }
        public TimeSpan ImageTime { get; private set; }
        
        public SingleResultStatistic(TimeSpan youtubeTime, TimeSpan imageTime)
        {
            YoutubeTime = youtubeTime;
            ImageTime = imageTime;
        }
    }

    [DataContract]
    public class RequestStatistics
    {
        [DataMember(Name = "groovesharktime")]
        public double GroovesharkTime { get; private set; }

        [DataMember(Name = "youtubetime")]
        public double YoutubeTime { get; private set; }

        [DataMember(Name = "imagetime")]
        public double ImageTime { get; private set; }

        public RequestStatistics(TimeSpan groovesharkTime, IEnumerable<SingleResultStatistic> singleStats)
        {
            GroovesharkTime = groovesharkTime.TotalMilliseconds;
            YoutubeTime = singleStats.Sum(p => p.YoutubeTime.TotalMilliseconds);
            ImageTime = singleStats.Sum(p => p.ImageTime.TotalMilliseconds);
        }
    }
}